package com.ruoyi.web.controller.performance;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.performance.domain.MonthlySummary;
import com.ruoyi.performance.service.IMonthlySummaryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 月度数据汇总Controller
 * 
 * @author eden
 * @date 2023-05-19
 */
@RestController
@RequestMapping("/performance/monthly")
public class MonthlySummaryController extends BaseController
{
    @Autowired
    private IMonthlySummaryService monthlySummaryService;

    /**
     * 查询月度数据汇总列表
     */
    @PreAuthorize("@ss.hasPermi('performance:monthly:list')")
    @GetMapping("/list")
    public TableDataInfo list(MonthlySummary monthlySummary)
    {
        startPage();
        List<MonthlySummary> list = monthlySummaryService.selectMonthlySummaryList(monthlySummary);
        return getDataTable(list);
    }

    /**
     * 导出月度数据汇总列表
     */
    @PreAuthorize("@ss.hasPermi('performance:monthly:export')")
    @Log(title = "月度数据汇总", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MonthlySummary monthlySummary)
    {
        List<MonthlySummary> list = monthlySummaryService.selectMonthlySummaryList(monthlySummary);
        ExcelUtil<MonthlySummary> util = new ExcelUtil<MonthlySummary>(MonthlySummary.class);
        util.exportExcel(response, list, "月度数据汇总数据");
    }

    /**
     * 获取月度数据汇总详细信息
     */
    @PreAuthorize("@ss.hasPermi('performance:monthly:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(monthlySummaryService.selectMonthlySummaryById(id));
    }

    /**
     * 新增月度数据汇总
     */
    @PreAuthorize("@ss.hasPermi('performance:monthly:add')")
    @Log(title = "月度数据汇总", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MonthlySummary monthlySummary)
    {
        return toAjax(monthlySummaryService.insertMonthlySummary(monthlySummary));
    }

    /**
     * 修改月度数据汇总
     */
    @PreAuthorize("@ss.hasPermi('performance:monthly:edit')")
    @Log(title = "月度数据汇总", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MonthlySummary monthlySummary)
    {
        return toAjax(monthlySummaryService.updateMonthlySummary(monthlySummary));
    }

    /**
     * 删除月度数据汇总
     */
    @PreAuthorize("@ss.hasPermi('performance:monthly:remove')")
    @Log(title = "月度数据汇总", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(monthlySummaryService.deleteMonthlySummaryByIds(ids));
    }
}
